import microAppConfigs from './main'
import BaseLayout from './layout'
import { ConfigProvider } from 'antd'
import React from 'react'
import ReactDOM from 'react-dom'
import { registerMicroApps, start, setDefaultMountApp } from 'qiankun'
import './style/normalize.css'
import 'antd/dist/antd.css'
import zhCN from 'antd/es/locale/zh_CN'
import shared from './shared'

function render() {
  const container = document.getElementById('root')
  ReactDOM.render(
    <ConfigProvider locale={zhCN}>
      <BaseLayout />
    </ConfigProvider>,
    container
  )
}

function initApp() {
  render()
  registerMicroApps([
    ...microAppConfigs.map(config => ({
      ...config,
      props: { shared }
    }))
  ])
  const PREFIX = './'
  let defaultUrl = PREFIX
  if (window.location.hash !== '#/') {
    defaultUrl = `${PREFIX}${window.location.hash}`
  }
  setDefaultMountApp(defaultUrl)
  start({ prefetch: false, sandbox: false })
}

initApp()
